Skip to main content

TermStruct<StructDef>

TermStruct is an other type that is unnecessarily complicated.

This time because it has to mess around with the struct definition; but even so the type definition should not be that hard to understand if we know what is doing

type StructInstance<SCtorDef extends StructCtorDef> = {
readonly [Field in keyof SCtorDef]: UtilityTermOf<ToPType<SCtorDef[Field]>>
}

type TermStruct<SDef extends StructDefinition> = Term<PStruct<SDef>> & {

readonly eqTerm: TermFn<[PStruct<SDef>], PBool>
readonly eq: ( other: Term<PStruct<SDef>> ) => TermBool

} &
IsSingelKey<SDef> extends true ? StructInstance<SDef[keyof SCtorDef]> : {};

Even with these simplifications it might seem a bit complex but really all is telling us is that it adds the struct properties (trough Structinstance) only if the struct can only have one single constructor; and adds nothing if it has more.

In fact we already encountered this method while introducing pmatch; we just didn't know that it was an utility term.

It then adds the eq method regardless of the struct definition.

eq

eq

parameter: other type: Term<PStruct<SDef>>

returns: TermBool

equivalent expression:

peqData.$( term as any ).$( other  as any )

Data equality